<template>
   <section class="main">
      <input id="toggle-all" class="toggle-all" type="checkbox" />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list">
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <!--class动态绑定类名， completed -->
        <li :class="{completed:item.flag}" v-for="item in data " :key="item.id">
          <div class="view">
            <input 
            class="toggle"
            type="checkbox"
             :checked="item.flag"
              @change="changeFlag(item.id,$event)" />
            <label>{{item.content}}</label>
            <button class="destroy" @click="delContent(item.id,)" ></button>
          </div>
        </li>
      </ul>
    </section>
</template>
 
<script>
export default {
 
  components: {},
  /* 接收 props只读 */
  props: {
    data:{
      type:Array,
      required: true,
    }
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
   changeFlag(id,e){
  this.$emit('changeFlag',id,e.target.checked)
   },
   /* 发起删除的请求 */
   delContent(id){
    this.$emit("delContent",id)
   }
  }
};
</script>

<style scoped>
     
</style>